package com.swinginwind.flexutils.components 
{
	import flash.display.DisplayObject;
	
	import mx.core.IFlexDisplayObject;
	import mx.effects.Blur;
	import mx.effects.Fade;
	import mx.events.TweenEvent;
	import mx.managers.PopUpManager;
	
	public class PopUpEffect
	{
		
		public function PopUpEffect()
		{
		}
		
		public static function Show(control:IFlexDisplayObject,parent:DisplayObject,modal:Boolean=true,effectType:String="blur",needCenter:Boolean=true):void
		{
			if(effectType == "blur")
			{
				var mShowEffect:Blur=new Blur();
				mShowEffect.blurXFrom=255;
				mShowEffect.blurYFrom=255;
				mShowEffect.blurXTo=0;
				mShowEffect.blurYTo=0;
				mShowEffect.target= control;
				mShowEffect.duration=300;
				
				PopUpManager.addPopUp(control,parent,modal);
				if(needCenter)
					PopUpManager.centerPopUp(control);
				mShowEffect.play();
			}
			else if(effectType == "fade")
			{
				var mShowEffect1:Fade=new Fade();
				mShowEffect1.alphaFrom = 0;
				mShowEffect1.alphaTo = 1;
				mShowEffect1.target= control;
				mShowEffect1.duration=300;
				PopUpManager.addPopUp(control,parent,modal);
				if(needCenter)
					PopUpManager.centerPopUp(control);
				mShowEffect1.play();
			}
			
		}
		public static function Hide(control:IFlexDisplayObject, effectType:String="blur"):void
		{
			if(effectType == "blur")
			{
				var mHideEffect:Blur=new Blur();
				mHideEffect.blurXFrom=0;
				mHideEffect.blurYFrom=0;
				mHideEffect.blurXTo=255;
				mHideEffect.blurYTo=255;
				mHideEffect.addEventListener(TweenEvent.TWEEN_END,function():void{
					PopUpManager.removePopUp(control);
				});
				mHideEffect.duration=300;
				mHideEffect.target=control;
				mHideEffect.play();
			}
			else if(effectType == "fade")
			{
				var mHideEffect1:Fade=new Fade();
				mHideEffect1.alphaFrom = 1;
				mHideEffect1.alphaTo = 0;
				mHideEffect1.addEventListener(TweenEvent.TWEEN_END,function():void{
					PopUpManager.removePopUp(control);
				});
				mHideEffect1.target= control;
				mHideEffect1.duration=100;
				mHideEffect1.play();
			}
		}
	}
}